/* 
  Copyright (c) SilverLining 2015
  Date:    2016-1-7
  File:    shim_process.h  
  Description: 

*/

#pragma once

namespace SL
{
	namespace M
	{
		ref class Process;

		typedef void (__stdcall *ProcessEntryCallback)(void);
		typedef bool (__stdcall *HandleMessageCallback)(m::message* m);

		/// <summary>
		/// Represent a native shim for managed processes.
		/// </summary>
		/// <remarks>This class is meant for internal use.</remarks>
		class shim_process : public m::process
		{
		public:
			shim_process();
			~shim_process();

			void * operator new(size_t sz);
			void operator delete(void * ptr);

			/// <summary>
			/// Invoke the native message handler for this process.
			/// </summary>
			/// <returns>True if a message was received.</returns>
			bool next_message();

			/// <summary>
			/// Initialize the object.
			/// </summary>
			/// <param name="pThis">The managed object to be used for initialization.</param>
			void set_process(Process^ pThis);

			/// <summary>
			/// Return the managed process related to this object.
			/// </summary>
			/// <returns>A managed process class.</returns>
			Process^ get_process() const;

			virtual std::wstring to_string() const;

		protected:
			virtual void process_entry();
			virtual bool handle_message(m::message* m);

		private:
			ProcessEntryCallback _ProcessEntryCallback;
			HandleMessageCallback _HandleMessageCallback;

			wchar_t* TypeName;
			void* _hProcess;
		};

	}
}